package cn.wolfcode.shop.cloud.web.advice;

import cn.wolfcode.shop.cloud.common.CommonAdvice;
import cn.wolfcode.shop.cloud.common.Result;
import cn.wolfcode.shop.cloud.util.MemberCodeMsg;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;



@ControllerAdvice
public class MemberAdviceController extends CommonAdvice {

    @ExceptionHandler(BindException.class)
    @ResponseBody
    public Result handler(BindException ex){
        //获取到 参数校验出错的信息
        System.out.println(ex.getAllErrors().get(0).getDefaultMessage());
        MemberCodeMsg memberCodeMsg = MemberCodeMsg.ARGUMENTS_OPT.filterArg(ex.getAllErrors().get(0).getDefaultMessage());
        return Result.error(memberCodeMsg);
    }

}
